package com.zzl.car.controller;

import com.github.pagehelper.PageInfo;
import com.zzl.car.entity.CarBaseInfo;
import com.zzl.car.entity.CarDetailInfo;
import com.zzl.car.service.CarDetailInfoService;
import com.zzl.car.service.ZzwCarDetailInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class ZzwCarDetailInfoController {

    @Autowired
    private ZzwCarDetailInfoService carDetailInfoService;
    @Autowired
    private CarDetailInfoService ZdpcarDetailInfoService;

    // 获得所有车辆具体信息 --> 分页
    @GetMapping("getAllCarDetailInfoPage")
    public PageInfo<CarDetailInfo> getAllCarDetailInfo(@RequestParam(value = "currentPage",defaultValue = "1") int currentPage){
        PageInfo<CarDetailInfo> carDetailInfoList = carDetailInfoService.getAllCarDetailInfoByPage(currentPage,8);

        System.out.println(carDetailInfoList.getSize());
        return carDetailInfoList;
    }

    /**
     * 添加车辆具体信息
     * @param map
     * @return 成功返回 1 失败返回 0
     */
    @PostMapping("addCarDetailInfo")
    public String addCarDetailInfo(@RequestBody Map map){
        return  carDetailInfoService.addCarDetailInfo(map);
    }


    /*
    * 获取所有可租赁的车辆信息，不分页（可租赁的车辆） 0 可租赁
    * */
    @GetMapping("/getAllCar")
    public List<CarDetailInfo> getAllCar(){
        return ZdpcarDetailInfoService.getAllCarByLoveCarScore();
    }

    /*
    * 根据传入的商标，租金，类型 获取到所有可租赁的车辆信息
    * */
    @PostMapping("/getCarByBranchAndRent")
    public List<CarDetailInfo> getCarByBranchAndRent(@RequestBody Map<String,Object>data){
        String branch =(String) data.get("branch");
        Integer rent = (Integer) data.get("rent");
        String type = (String) data.get("type");
        System.out.println(branch);
        System.out.println(rent);
        System.out.println(type);
        List<CarDetailInfo> carByBranchAndTypeAndRent = ZdpcarDetailInfoService.getCarByBranchAndTypeAndRent(branch, type, rent);
        for(CarDetailInfo c:carByBranchAndTypeAndRent) {
            System.out.println(c);
        }
        return carByBranchAndTypeAndRent;
    }


    // 修改车辆信息
    @PostMapping("/modifyCarDetailInfo")
    public String modifyCarDetailInfoById(@RequestBody Map<String, Object> map){
        return carDetailInfoService.modifyCarDetailInfoById(map);
    }

    // 条件查询 brand detailType
    @GetMapping("/searchCarDetailInfo")
    public PageInfo<CarDetailInfo> searchCarDetailInfo(@RequestParam("carPlate")String carPlate,
                                                   @RequestParam(value = "state",required = false)Integer state,
                                                   @RequestParam(value = "currentPage",defaultValue = "1") int currentPage){

        return carDetailInfoService.searchCarDetailInfo(carPlate,state,currentPage);
    }

    @GetMapping("/deleteCarDetailInfo")
    public String deleteCarDetailInfo(@RequestParam("id") Integer id) {

        return carDetailInfoService.deleteCarDetailInfo(id);
    }

}
